package edu.biwu.request;

import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;

/**
 *  HttpServletRequest中的方法
 *     public String getContextPath():获取当前应用的Application Context
 *     public String getQueryString():获取查询字符串，就是?后边的参数xx=xx&xx=xx,例如"username=abc&password=123456"
 *     public String getMethod():获取的是当前的请求方式
 *     public String getRequestURI():获取的是当前请求的绝对路径(带有主机和端口号)，不包含?后边的参数
 *     public StringBuffer getRequestURL():获取的是请求行中的路径(URL路径一部分),不包含?后面的参数
 */
@WebServlet("/req/demo01")
public class RequestDemo01 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println(request.getContextPath());// /day06-response-request,获取当前应用的Application Context
        System.out.println(request.getMethod());// GET 获取的是当前的请求方式 GET/POST
        System.out.println(request.getQueryString());//获取的是查询字符串,其实就是请求的?后面的参数xx=xx&xx=xx,例如"username=abc&password=123456"
        System.out.println(request.getRequestURI());//  /day06-response-request/req/demo01
        System.out.println(request.getRequestURL());//  http://localhost:8080/day06-response-request/req/demo01
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
